// 只针对一类业务的操作 - 信息import Mock from 'mockjs'
const Mock = require('mockjs'); // 假数据
const Random = Mock.Random

module.exports = function (app) {
    const prefix = '/api/message/';

    app.get(prefix + 'list', (req, res) => {
        const code = 200;
        const msg = '';
        let unreadList = []
        for (var i = 0, l = 3; i < l; i++) {
            unreadList.push(Mock.mock({
                title: Random.cword(10, 15),
                create_time: '@date',
                msgid: Random.increment(100)
            }))
        }
        let readedList = []
        for (var i2 = 0, l2 = 4; i2 < l2; i2++) {
            readedList.push(Mock.mock({
                title: Random.cword(10, 15),
                create_time: '@date',
                msgid: Random.increment(100)
            }))
        }
        let trashList = []
        for (var i3 = 0, l3 = 2; i3 < l3; i3++) {
            trashList.push(Mock.mock({
                title: Random.cword(10, 15),
                create_time: '@date',
                msgid: Random.increment(100)
            }))
        }
        const data = {
            unread: unreadList,
            readed: readedList,
            trash: trashList
        }
        const time = +(new Date);
        const result = {code, data, msg, time};
        return res.end(JSON.stringify(result));
    });
    app.get(prefix + 'query', (req, res) => {
        const code = 200;
        const msg = '';
        const data = Mock.mock({ // 生成
            'info': `<divcourier style="font-weight:=normal;font-size:=12px;line-height:=18px;white-space:=pre;"><div>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: medium;">这是消息内容，这个内容是使用<span style="color: rgb(255, 255, 255); background-color: rgb(28, 72, 127);">富文本编辑器</span>编辑的，所以你可以看到一些<span style="text-decoration-line: underline; font-style: italic; color: rgb(194, 79, 74);">格式</span></span></div><ol><li>你可以查看Mock返回的数据格式，和api请求的接口，来确定你的后端接口的开发</li><li>使用你的真实接口后，前端页面基本不需要修改即可满足基本需求</li><li>快来试试吧</li></ol><p>${Random.csentence(100, 200)}</p></divcourier>`
        });
        const time = +(new Date);
        const result = {code, data, msg, time};
        return res.end(JSON.stringify(result));
    });
}
